
<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="修改时间">
                <el-date-picker
                    v-model="dateRange"
                    style="width: 240px"
                    value-format="yyyy-MM-dd"
                    type="daterange"
                    range-separator="-"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                ></el-date-picker>
            </el-form-item>
            <el-form-item label="文档名称" prop="docName">
                <el-input
                    v-model="queryParams.docName"
                    placeholder="请输入文档名称"
                    clearable
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
                </el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>

            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                    type="primary"
                    icon="el-icon-upload2"
                    size="mini"
                    @click="handleImport"
                >导入修订文档
                </el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" :disabled="multipleDoc" @click="handleCompareDoc" size="mini">对比分析</el-button>
            </el-col>
        </el-row>
        <el-table v-loading="loading" :data="docList" @selection-change="handleSelectionChangeDoc">
            <el-table-column type="selection" width="55"></el-table-column>/
            <el-table-column type="index" label="序号" width="55" >
                <template slot-scope="scope">
                    <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
                </template>
            </el-table-column>
            <el-table-column label="文档名称" align="center" prop="docName"></el-table-column>
            <el-table-column label="类型" align="center" prop="docType"></el-table-column>
            <el-table-column label="修改时间" align="center" prop="operationTime"></el-table-column>
            <el-table-column label="版本" align="center" prop="version"></el-table-column>
            <el-table-column label="操作" align="center" width="240px">
                <template slot-scope="scope">
                    <el-button type="text" size="mini" @click="handleEditDoc(scope.row)">编辑</el-button>
                    <el-button type="text" size="mini" @click="handleViewDoc(scope.row)">查看</el-button>
                    <el-button type="text" size="mini" @click="handleVersion(scope.row)">修改版本信息</el-button>
                    <el-button type="text" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                    <el-button type="text" size="mini" @click="handleNeedDiffTable(scope.row)">需求分歧报告</el-button>
                    <el-button type="text" size="mini" @click="handleContent(scope.row)">内容统计</el-button>
                    <el-button type="text" size="mini" @click="handleExportDoc(scope.row)">导出</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
        />
        <!---修改版本信息--->
        <el-dialog
            title="文档版本信息"
            :visible.sync="versionOpen"
            width="400px"
            @close="closeVersion"
            append-to-body
            :close-on-click-modal="false">
            <el-form
                ref="versionFormRef" :model="versionForm" :rules="versionRules" label-width="80px">
                <el-form-item label="名称" prop="docName">
                    {{versionForm.docName}}
                </el-form-item>
                <el-form-item label="版本" prop="version">
                    <el-input v-model="versionForm.version"></el-input>
                </el-form-item>
                <el-form-item label="格式" prop="docType">
                    {{versionForm.docType}}
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitVersionForm">确 定</el-button>
                <el-button @click="versionOpen = false">取 消</el-button>
            </div>
        </el-dialog>
        <!----需求分歧表--->
        <el-dialog
            title="需求分歧报告"
            :visible.sync="needOpen"
            width="80%"
            append-to-body
            @close="closeNeedDia"
            :close-on-click-modal="false">
            <el-form ref="docForm" :model="docForm" inline label-width="120px">
                <el-form-item label="文档名称：">{{docForm.docName}}</el-form-item>
                <el-form-item label="修改时间：">{{docForm.operationTime}}</el-form-item>
                <el-form-item label="文件版本：">{{docForm.version}}</el-form-item>
                <el-form-item style="float: right">
                    <el-button type="primary" size="mini" v-print="print">打印</el-button>
                    <el-button type="primary" size="mini" @click="handleExportNeed">导出</el-button>
                </el-form-item>
            </el-form>
            <el-table v-loading="needTableLoading" ref="needTableRef" :data="needTable" @selection-change="handleSelectionChange" height="40vh" id="printArea">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column type="index" label="序号" width="55" ></el-table-column>
                <el-table-column label="原文内容" align="center" prop="chooseContent"></el-table-column>
                <el-table-column label="意见建议" align="center" prop="remarkAdvice"></el-table-column>
                <el-table-column label="提出理由" align="center" prop="remarkReason"></el-table-column>
                <el-table-column label="处理意见" align="center" prop="remarkResolution"></el-table-column>
                <el-table-column label="对接状态" align="center" prop="remarkDockingStatus"></el-table-column>
                <el-table-column label="所内意见" align="center" prop="remarkStationAdvice"></el-table-column>
                <el-table-column label="重要程度" align="center" prop="remarkIsNeed">
                    <template slot-scope="scope">
                        <span v-if="scope.row.remarkIsNeed===1">紧急</span>
                        <span v-else-if="scope.row.remarkIsNeed===2">重要</span>
                        <span v-else>一般</span>
                    </template>
                </el-table-column>
                <el-table-column label="研总要求" align="center" prop="remarkDocRequire"></el-table-column>
                <el-table-column label="操作" align="center" width="120px">
                    <template slot-scope="scope">
                        <el-button type="text" size="mini" @click="handleDeleteNeedDiff(scope.row)">删除</el-button>
                        <el-button type="text" size="mini" @click="handleEditNeedDiff(scope.row)">修改</el-button>
                        <el-button type="text" size="mini" @click="handlePosition(scope.row)">定位</el-button>
                    </template>
                </el-table-column>
            </el-table>

        </el-dialog>
        <!---文档统计分析----->
        <el-dialog
            title="文档统计分析"
            :visible.sync="docContentOpen"
            width="80%"
            append-to-body
            :close-on-click-modal="false">
            <el-form ref="docFormRef" :model="docForm" inline label-width="120px" >
                <el-row>
                    <el-form-item style="float:right;">
                        <el-button type="primary" size="mini" v-print="printDocContent">打印</el-button>
                        <el-button type="primary" size="mini" @click="handleExportContent">导出</el-button>
                    </el-form-item>
                </el-row>

                <div id="printDocContentArea">
                    <el-row>
                        <el-form-item label="文档名称：">{{docForm.docName}}</el-form-item>
                        <el-form-item label="修改时间：">{{docForm.operationTime}}</el-form-item>
                        <el-form-item label="文件版本：">{{docForm.version}}</el-form-item>

                    </el-row>
                    <h4>分歧需求统计：</h4>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="意见建议：">{{docForm.countAdvice}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="已对接：">{{docForm.countDockingStatus}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="研总确认：">{{docForm.countDocRequire}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="理由明确：">{{docForm.countReason}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="所内意见：">{{docForm.countInstitute}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="处理意见：">{{docForm.countResolution}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="需求明确：">{{docForm.countIsNeed}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item>
                                <el-button type="text" size="mini" @click="handleNeedDiffTable(docForm)">查看需求分歧表</el-button>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <h4>基本信息统计：</h4>
                    <el-row>
                        <el-form-item label="字数：">{{docForm.countWord}}</el-form-item>
                    </el-row>
                    <el-row>
                        <el-form-item label="段落数：">{{docForm.countParagraph}}</el-form-item>
                    </el-row>
                    <el-row>
                        <el-form-item label="章节数：">{{docForm.countChapter}}</el-form-item>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="高频词：">{{docForm.countHighFrequency}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-button type="text" size="mini" @click="showHighWords">查看</el-button>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="语义相近词：">{{docForm.countSynonym}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-button type="text" size="mini" @click="showSameWords">查看</el-button>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="新增专业词：">{{docForm.countPro}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-button type="text" size="mini" @click="showProjectWords">查看</el-button>
                        </el-col>
                    </el-row>
                </div>
            </el-form>
        </el-dialog>
        <!---文档统计设置--->
        <el-dialog
            title="文档信息统计设置"
            :visible.sync="docContentSetOpen"
            width="600px"
            append-to-body
            :close-on-click-modal="false">
            <el-form ref="docSetFormRef" :model="docSetForm" label-width="180px">
                <el-form-item label="参与统计的需求重要程度" prop="importance">
                    <el-radio-group v-model="docSetForm.importance">
                        <el-radio :label="1">紧急</el-radio>
                        <el-radio :label="2">重要</el-radio>
                        <el-radio :label="3">一般</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="按照章节数量统计" prop="chapter">
                    <el-checkbox v-model="docSetForm.chapter"></el-checkbox>
                </el-form-item>
                <el-form-item label="仅统计总数" prop="allWords">
                    <el-checkbox v-model="docSetForm.allWords"></el-checkbox>
                </el-form-item>
                <el-form-item label="字数是否包含标点符号" prop="punctuation">
                    <el-checkbox v-model="docSetForm.punctuation"></el-checkbox>
                </el-form-item>
                <el-form-item label="段落是否包含图片和题注" prop="picMark">
                    <el-checkbox v-model="docSetForm.picMark"></el-checkbox>
                </el-form-item>
                <el-form-item label="段落是否包含表格和题注" prop="tableMark">
                    <el-checkbox v-model="docSetForm.tableMark"></el-checkbox>
                </el-form-item>
                <el-form-item label="段落是否包含章节标题" prop="chapterTitle">
                    <el-checkbox v-model="docSetForm.chapterTitle"></el-checkbox>
                </el-form-item>
                <el-form-item label="高频词汇率阈值" prop="highWordsThreshold">
                    <el-input-number v-model="docSetForm.highWordsThreshold" :min="1" :max="10"></el-input-number>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitDocSetForm">确 定</el-button>
                <el-button @click="cancelDocSet">取 消</el-button>
            </div>
        </el-dialog>
        <!----高频词------>
        <el-dialog
            title="高频词列表"
            :visible.sync="highWordsOpen"
            width="60%"
            append-to-body
            :close-on-click-modal="false">
            <el-form ref="docFormRef" :model="docForm" inline label-width="120px">
                <el-form-item label="文档名称：">{{docForm.docName}}</el-form-item>
                <el-form-item label="修改时间：">{{docForm.operationTime}}</el-form-item>
                <el-form-item label="文件版本：">{{docForm.version}}</el-form-item>
                <el-form-item style="float: right">
                    <el-button type="primary" size="mini">打印</el-button>
                    <el-button type="primary" size="mini">导出</el-button>
                </el-form-item>
            </el-form>
            <el-table :data="highWordsTable" height="40vh">
                <el-table-column type="index" label="序号" width="55" ></el-table-column>
                <el-table-column label="高频词" align="center" prop="highWords"></el-table-column>
                <el-table-column label="出现次数" align="center" prop="counts"></el-table-column>
            </el-table>
        </el-dialog>
        <!------语义相近词----->
        <el-dialog
            title="语义相近词列表"
            :visible.sync="sameWordsOpen"
            width="60%"
            append-to-body
            :close-on-click-modal="false">
            <el-form ref="docFormRef" :model="docForm" inline label-width="120px">
                <el-form-item label="文档名称：">{{docForm.docName}}</el-form-item>
                <el-form-item label="修改时间：">{{docForm.operationTime}}</el-form-item>
                <el-form-item label="文件版本：">{{docForm.version}}</el-form-item>
                <el-form-item style="float: right">
                    <el-button type="primary" size="mini">打印</el-button>
                    <el-button type="primary" size="mini">导出</el-button>
                </el-form-item>
            </el-form>
            <el-table :data="sameWordsTable" height="40vh">
                <el-table-column type="index" label="序号" width="55" ></el-table-column>
                <el-table-column
                    v-for="i in sameWordsTableHeader"
                    :key="i.enName"
                    :label="i.cnName"
                    align="center"
                    :prop="i.enName"></el-table-column>
                <el-table-column label="操作" align="center" >

                </el-table-column>
            </el-table>
        </el-dialog>
        <!----专业词---->
        <el-dialog
            title="专业词列表"
            :visible.sync="projectWordsOpen"
            width="60%"
            append-to-body
            :close-on-click-modal="false">
            <el-form ref="docFormRef" :model="docForm" inline label-width="120px">
                <el-form-item label="文档名称：">{{docForm.docName}}</el-form-item>
                <el-form-item label="修改时间：">{{docForm.operationTime}}</el-form-item>
                <el-form-item label="文件版本：">{{docForm.version}}</el-form-item>
                <el-form-item style="float: right">
                    <el-button type="primary" size="mini">打印</el-button>
                    <el-button type="primary" size="mini">导出</el-button>
                </el-form-item>
            </el-form>
            <el-table :data="projectWordsTable" height="40vh">
                <el-table-column type="index" label="序号" width="55" ></el-table-column>

                <el-table-column label="操作" align="center" >

                </el-table-column>
            </el-table>
        </el-dialog>
        <!-----导入------->
        <el-dialog title="上传文档" :visible.sync="uploadOpen" width="500px" append-to-body>
            <el-upload
                style="margin: auto;text-align: center;margin-bottom: 20px;"
                ref="upload"
                :limit="5"
                accept=".doc, .pdf, .docx"
                action=""
                multiple
                :headers="upload.headers"
                :disabled="upload.isUploading"
                :on-progress="handleFileUploadProgress"
                :on-success="handleFileSuccess"
                :on-change="changeFile"
                :file-list="fileList"
                :auto-upload="false"
                drag
            >
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                <div class="el-upload__tip text-center" slot="tip">
                    <span>仅允许导入doc、docx、pdf格式文件。</span>
                </div>
            </el-upload>
            <el-form :model="relatedModel" ref="relatedRef" :rules="relatedRules" label-width="120px">
                <el-form-item label="关联文档：" prop="relatedDoc">
                    <el-select v-model="relatedModel.relatedDoc" filterable clearable style="width: 100%">
                        <el-option v-for="(i,index) in docOptions" :key="index" :value="i.seriesId" :label="i.docName+'.'+i.docType+'_'+i.version">
                            <span>{{i.docName}}.{{i.docType}}_{{i.version}}</span>
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitFileForm">确 定</el-button>
                <el-button @click="uploadOpen = false">取 消</el-button>
            </div>
        </el-dialog>
        <!--修改需求分歧--->
        <el-dialog
            title="修改需求分歧信息"
            :visible.sync="remarkOpen"
            width="780px"
            append-to-body
            @close="dialogClose"
        >
            <el-form ref="remarkFormRef" :model="remarkForm" label-width="80px">
                <el-form-item label="批注段落" prop="">
                    <span>{{ remarkForm.chooseContent }}</span>
                </el-form-item>
                <el-form-item label="批注内容">
                    <el-input
                        type="textarea"
                        :rows="2"
                        v-model="remarkForm.remarkContent"
                        placeholder="请输入批注内容"
                    />
                </el-form-item>
                <el-form-item label="意见建议">
                    <el-input
                        type="textarea"
                        :rows="2"
                        v-model="remarkForm.remarkAdvice"
                        placeholder="请输入意见建议"
                    />
                </el-form-item>
                <el-form-item label="提出理由">
                    <el-input
                        type="textarea"
                        :rows="2"
                        v-model="remarkForm.remarkReason"
                        placeholder="请输入提出理由"
                    />
                </el-form-item>
                <el-form-item label="处理意见">
                    <el-input
                        type="textarea"
                        :rows="2"
                        v-model="remarkForm.remarkResolution"
                        placeholder="请输入处理意见"
                    />
                </el-form-item>
                <el-form-item label="对接状态">
                    <el-input
                        type="textarea"
                        :rows="2"
                        v-model="remarkForm.remarkDockingStatus"
                        placeholder="请输入对接状态"
                    />
                </el-form-item>
                <el-form-item label="所内意见">
                    <el-input
                        type="textarea"
                        :rows="2"
                        v-model="remarkForm.remarkStationAdvice"
                        placeholder="请输入所内意见"
                    />
                </el-form-item>
                <el-form-item label="重要程度">
                    <el-radio-group v-model="remarkForm.remarkIsNeed">
                        <el-radio :label="1">紧急</el-radio>
                        <el-radio :label="2">重要</el-radio>
                        <el-radio :label="3">一般</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="研总要求">
                    <el-input
                        type="textarea"
                        :rows="2"
                        v-model="remarkForm.remarkDocRequire"
                        placeholder="请输入研总要求"
                    />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="dialogClose">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import {
    getDocList,
    delDoc,
    getRemarkList,
    exportRemarkList,
    checkDocComparison,
    docManageImportFiles,
    getOutInDocRelList,
    editDoc
} from "@/api/compare/index"
import {getToken} from "@/utils/auth";
import { saveAs } from 'file-saver'
import {blobValidate} from "@/utils/ruoyi";
export default {
    data() {
        return {
            print: {
                id: 'printArea',
                popTitle: '打印', // 打印配置页上方标题
                extraHead: '', //最上方的头部文字，附加在head标签上的额外标签,使用逗号分隔
                preview: '', // 是否启动预览模式，默认是false（开启预览模式，可以先预览后打印）
                previewTitle: '', // 打印预览的标题（开启预览模式后出现）,
                previewPrintBtnLabel: '', // 打印预览的标题的下方按钮文本，点击可进入打印（开启预览模式后出现）
                zIndex: '', // 预览的窗口的z-index，默认是 20002（此值要高一些，这涉及到预览模式是否显示在最上面）
                previewBeforeOpenCallback() {
                    // this.isPrint = false;
                    // this.$refs.needTableRef.doLayout()
                }, //预览窗口打开之前的callback（开启预览模式调用）
                previewOpenCallback() {}, // 预览窗口打开之后的callback（开启预览模式调用）
                beforeOpenCallback() {}, // 开启打印前的回调事件
                openCallback() {}, // 调用打印之后的回调事件
                closeCallback() {
                    // this.isPrint = true;
                }, //关闭打印的回调事件（无法确定点击的是确认还是取消）
                url: '',
                standard: '',
                extraCss: '',
            },
            printDocContent: {
                id: 'printDocContentArea',
                popTitle: '打印', // 打印配置页上方标题
                extraHead: '', //最上方的头部文字，附加在head标签上的额外标签,使用逗号分隔
                preview: '', // 是否启动预览模式，默认是false（开启预览模式，可以先预览后打印）
                previewTitle: '', // 打印预览的标题（开启预览模式后出现）,
                previewPrintBtnLabel: '', // 打印预览的标题的下方按钮文本，点击可进入打印（开启预览模式后出现）
                zIndex: '', // 预览的窗口的z-index，默认是 20002（此值要高一些，这涉及到预览模式是否显示在最上面）
                previewBeforeOpenCallback() {

                }, //预览窗口打开之前的callback（开启预览模式调用）
                previewOpenCallback() {}, // 预览窗口打开之后的callback（开启预览模式调用）
                beforeOpenCallback() {}, // 开启打印前的回调事件
                openCallback() {}, // 调用打印之后的回调事件
                closeCallback() {

                }, //关闭打印的回调事件（无法确定点击的是确认还是取消）
                url: '',
                standard: '',
                extraCss: '',
            },
            isPrint:true,  //是否是打印
            dateRange:[],
            queryParams:{
                docName:'',
                pageSize:10,
                pageNum:1,
            },
            total:1,
            docList:[],
            loading:false,
            //需求分歧
            needOpen:false,
            currentRow:{},  //当前选中行
            needTableLoading:false,
            docForm:{
                docName:'',
                operationTime:'',
                version:'',
                //文档统计
                countAdvice:null,
                countDockingStatus:null,
                countDocRequire:null,
                countReason:null,
                countInstitute:null,
                countResolution:null,
                countIsNeed:null,
                countWord:null,
                countParagraph:null,
                countChapter:null,
                countHighFrequency:null,
                countSynonym:null,
                countPro:null
            },
            needTable:[],
            needIds:[],
            //文档统计
            docContentOpen:false,
            //文档设置
            docContentSetOpen:false,
            docSetForm:{
                importance:1,
                chapter:'',
                allWords:'',
                punctuation:'',
                picMark:'',
                tableMark:'',
                chapterTitle:'',
                highWordsThreshold:1,
            },
            //高频词
            highWordsOpen:false,
            highWordsTable:[],
            //语义相近词
            sameWordsOpen:false,
            sameWordsTable:[],
            sameWordsTableHeader:[
                {
                    enName:"word1",
                    cnName:'词1'
                },
                {
                    enName:"word2",
                    cnName:'词2'
                },
                {
                    enName:"word3",
                    cnName:'词3'
                },
            ],
            //专业词
            projectWordsOpen:false,
            projectWordsTable:[],
            //版本
            versionOpen:false,
            versionForm:{
                docName:'',
                version:'',
                docType:'',
            },
            versionRules:{
                version:[{required:true,message:'版本不可为空',trigger:'blur'}]
            },
            multipleDoc:true,
            ids:[],  //勾选的文档id
            uploadOpen:false,
            upload: {
                // 是否禁用上传
                isUploading: false,
                // 设置上传的请求头部
                headers: {Authorization: "Bearer " + getToken()},
                // 上传的地址
                url: process.env.VUE_APP_BASE_API + "/common/upload"
            },
            relatedModel:{   //关联文档
                relatedDoc:'',   //关联文档名称
            },
            relatedRules:{
                relatedDoc:[{required:true,message:'关联文档不可为空',trigger:'blur'}]
            },
            docOptions:[],  //关联文档list（出入库管理中需求库中的所有文档）
            fileList:null,
            // 新增批注是否显示弹出层
            remarkOpen: false,
            //新增批注数据
            remarkForm: {
                domId:'',   //前端需要 区分左右两侧文档
                id: null, // 批注文档id---主键唯一
                remarkContent: "", // 批注内容
                pageNum: "", // 当前标注所在的PDF页码
                remarkAdvice:'',  //意见建议
                remarkReason:'',   //提出理由
                remarkResolution:'',   //处理意见
                remarkDockingStatus:'',  //对接状态
                remarkStationAdvice:'',//所内意见
                remarkIsNeed:1,  //是否需要
                remarkDocRequire:'',  //研总要求
                chooseContent:"",  //选中要标注的文内容
                topPdf:'',    //  选中的内容的top
                cachePdf:"",   //pdf缓存
                docId:'',   //当前添加标注的文档id
                top:'',  //
            },

        }
    },
    mounted() {
        getOutInDocRelList().then(res=>{
            this.docOptions = res.data;
        })
        this.handleQuery();
    },
    methods: {

        handleQuery(){
            this.queryParams.pageNum = 1;
            this.getList();
        },
        resetQuery(){
            this.resetForm("queryForm");
            this.dateRange = [];
        },
        getList(){
            getDocList(this.addDateRange(this.queryParams, this.dateRange)).then(res=>{
                this.docList = res.rows;
                this.total = res.total;
            })
        },
        //编辑文档内容。 2025-02-11修改为打开本地文件
        handleEditDoc(row){
            editDoc({id:row.id}).then(response => {
                console.log(response.data)
            })
            // this.$router.push({
            //     path:'/compare/editDoc',
            //     query:{
            //         type:'editDoc',
            //         id:row.id
            //     }
            // })
        },
        //查看文档  能够查看所有的修订内容，支持用户在其基础上进行进一步“批注”（需求分歧批注）。支持用户对历史批准内容进行增删改查。
        handleViewDoc(row){
            this.$router.push({
                path:'/compare/viewDoc',
                query:{
                    sourceFileMountPath:row.docPath,
                    sourceFileId:row.id,   //源文件
                }
            })
        },
        //修改版本信息
        handleVersion(row){
            this.versionOpen = true;
            // this.versionForm = JSON.parse(JSON.stringify(row));
            this.versionForm = row;
        },
        //关闭版本弹框
        closeVersion(){
            // this.$refs.versionFormRef.resetFields();
            this.versionOpen = false;
        },
        submitVersionForm(){
            this.$refs["versionFormRef"].validate(valid => {
                if(valid){
                    this.versionOpen = false;
                }
            })
        },
        //删除文档
        handleDelete(row){
            this.$modal.confirm('是否确认删除名称为"' + row.docName + '"的文档？').then(function () {
                return delDoc(row.id);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => {

            });
        },
        //需求分歧表
        handleNeedDiffTable(row){
            this.needOpen = true;

            this.docForm = JSON.parse(JSON.stringify(row));
            this.getNeedLsit(row.id);
        },
        getNeedLsit(id){
            getRemarkList({docId:id}).then(res=>{
                this.needTable = res.rows;
            })
        },
        //关闭需求分歧表
        closeNeedDia(){
            this.needOpen = false;
            this.needIds = [];
            this.$refs.needTableRef.clearSelection();
        },
        //勾选需求分歧表
        handleSelectionChange(val) {
            this.needIds = val.map(item => {return item.id});
        },
        //导出需求分歧
        handleExportNeed(){
            let _this = this;
            console.log(_this.needIds)
            if(this.needIds.length>0){
                this.$modal.confirm('是否确认导出选中的需求分歧信息？').then(function () {
                    // _this.download('/contras/remark/export', {
                    //     // idList:JSON.stringify(_this.needIds),
                    //     id:_this.needIds.toString(),
                    // }, `需求分歧报告_${new Date().getTime()}.xlsx`)
                    exportRemarkList({id:_this.needIds.toString()}).then(res=>{
                        console.log(res);
                        _this.download(res, `需求分歧报告_${new Date().getTime()}`)
                    })
                }).then(() => {
                    // this.$modal.msgSuccess("导出成功");
                }).catch(() => {

                });
            }else{
                this.$modal.confirm('是否确认导出当前文档全部需求分歧信息？').then(function () {
                    _this.download('/contras/remark/export', {}, `需求分歧报告_${new Date().getTime()}.xlsx`)
                }).then(() => {
                    this.getNeedLsit(this.docForm.id);
                    // this.$modal.msgSuccess("导出成功");
                }).catch(() => {

                });
            }
        },
        download(result, name) {
            const blob = new Blob([result], {
                type: 'application/vnd.ms-excel',
            });
            const url = window.URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.style.display = 'none';
            link.href = url ;
            link.download = `${name}.xlsx`;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        },
        //删除（备注）需求分歧
        handleDeleteNeedDiff(row){

        },
        //修改备注信息
        handleEditNeedDiff(row){
            this.remarkOpen = true;
            this.remarkForm = row;
        },
        //定位
        handlePosition(row){
            console.log(row)
            this.$router.push({
                path:'/compare/showNeedReport',
                query:{
                    type:'remarkPosition',
                    sourceFileId:row.docId,   //源文件
                    sourceFileMountPath:this.docForm.docPath,
                    infoStr:JSON.stringify(row),
                }
            })
        },
        //内容统计
        handleContent(row){
            this.docContentOpen = true;
            this.docForm = JSON.parse(JSON.stringify(row));
        },
        //导出内容统计
        handleExportContent(){
            console.log(this.docForm.id)
            this.download('/contras/doc/export', {id:this.docForm.id}, `文档统计报告_${new Date().getTime()}.xlsx`)
        },
        //文档设置
        handleDocSet(){
          this.docContentSetOpen = true;
        },
        //提交文档设置
        submitDocSetForm(){
            this.$refs["docSetFormRef"].validate(valid => {
                if (valid) {

                }
            })
        },
        cancelDocSet(){
            this.resetForm("docSetFormRef");
            this.docContentSetOpen = false;
        },
        //查看高频词汇
        showHighWords(){
            this.highWordsOpen = true;
        },
        //查看语义相近词
        showSameWords(){
            this.sameWordsOpen = true;
        },
        //查看专业词
        showProjectWords(){
            this.projectWordsOpen = true;
        },
        //导入
        handleImport(){
            this.uploadOpen = true;
        },
        //勾选两条进行文档对比
        handleSelectionChangeDoc(selection){
            this.multipleDoc = selection.length!==2;
            this.ids = selection.map(item=>{return item.id})
        },
        //勾选两个文档进行对比
        handleCompareDoc(){
            const loading = this.$loading({
                lock: true,
                text: '正在进行文档对比，请稍后',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            checkDocComparison({id1:this.ids[0],id2:this.ids[1]}).then(res => {
                loading.close();
            }).catch(()=>{
                loading.close();
            })
        },
        //导出文档
        handleExportDoc(){

        },
        // 文件上传中处理
        handleFileUploadProgress(event, file, fileList) {
            this.upload.isUploading = true;
        },
        // 文件上传成功处理
        handleFileSuccess(response, file, fileList) {
            this.upload.isUploading = false;
            this.uploadSuccess();
        },
        //文件上传成功
        uploadSuccess(){
            this.uploadOpen = false;
            this.$refs.upload.clearFiles();
            this.$modal.msgSuccess("导入成功");
            this.getList();
        },
        //变更文件，判断是否可以上传文件
        changeFile(file,fileList){
            console.log(file);
            this.fileList = fileList;
            console.log(fileList);
        },
        // 提交上传文件
        submitFileForm() {
            this.$refs.relatedRef.validate((valid) => {
                if(valid){
                    console.log(this.fileList)
                    this.param = new FormData();

                    // let arr = []
                    for(var i = 0;i<this.fileList.length;i++){
                        // this.param.append('file'+(i+1),this.fileList[i].raw);
                        this.param.append('files',this.fileList[i].raw);
                    }
                    // this.param.append('files',this.fileList);
                    this.param.append("seriesId",this.relatedModel.relatedDoc)
                    docManageImportFiles(this.param).then(res=>{
                        this.uploadSuccess();
                    });
                }
            })
        },
        //修改批注
        submitForm(){
            this.remarkOpen = false;
        },
        //添加批注模态框>取消按钮
        dialogClose() {
            this.remarkOpen = false;
            this.$refs.remarkFormRef.resetFields();
        },
    }
}
</script>
<style>
@media print{
    ::v-deep #printArea table {
        table-layout: fixed !important;
    }
    ::v-deep .el-table__header-wrapper .el-table__header {
        width: 100% !important;
    }
    ::v-deep .el-table__body-wrapper .el-table__body {
        width: 100% !important;
    }
    ::v-deep .el-table .cell.el-tooltip {
        text-overflow: clip;
        white-space: normal;
        min-width: none;
        width: auto !important;
        border: none !important;
    }
}

</style>
